package cn.ac.siom.query.action;

import cn.ac.siom.query.service.ITab_orgService;
import cn.ac.siom.query.util.action.DefaultAction;
import cn.ac.siom.query.vo.Tab_org;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@SuppressWarnings("unchecked")
@Controller
@RequestMapping(value = "/home/*")
public class Tab_orgAction extends DefaultAction {
    @Resource
    private ITab_orgService tab_orgService;

    /**
     * 激光通讯没用此接口
     */
    @RequestMapping(value = "tab_org_list")
    public void tab_org_Conference_list(HttpServletRequest request, HttpServletResponse response) {
        response.setHeader("Access-Control-Allow-Origin", "*");
        try {
            insertAccessinfo(request,"");
            super.printObjectToList(response, "allTab_org", this.tab_orgService.list());
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

    /**
     *
     * @param request
     * @return
     * @throws Exception
     */
    @ResponseBody
    @RequestMapping(value="findAllByParams", method= RequestMethod.GET,produces="application/json;charset=UTF-8")
    public Map findAllByParams(HttpServletRequest request,HttpServletResponse response) {
        response.setHeader("Access-Control-Allow-Origin", "*");
        try{
            insertAccessinfo(request,"首页相关机构");
            Map params=getParameterMap(request);
            return this.tab_orgService.findAllParams(params);
        }catch (Exception e){
            e.printStackTrace();
            return null;
        }
    }

    /**
     * 激光通讯没用此接口
     */
    @ResponseBody
    @RequestMapping(value="findNO_Tab_org", method= RequestMethod.GET,produces="application/json;charset=UTF-8")
    public List<Tab_org> findNO(HttpServletRequest request, Integer i_id) throws SQLException {
        insertAccessinfo(request,"");
        List<Tab_org>  tab_org = (List<Tab_org>) this.tab_orgService.list_NO(i_id);
        return tab_org;
    }

    /**
     * 激光通讯没用此接口
     */
    @ResponseBody
    @RequestMapping(value="findPage_Tab_org", method= RequestMethod.GET,produces="application/json;charset=UTF-8")
    public Map<String, Object> findPage(HttpServletRequest request, Integer rownum, Integer page_id) throws SQLException {
        insertAccessinfo(request,"");
        List<Tab_org>  tab_orgs = (List<Tab_org>) this.tab_orgService.list_page(rownum,page_id);
        Integer cont=this.tab_orgService.list_count();
        Map<String,Object> map = new HashMap<>();
        map.put("tab_orgs",tab_orgs);
        map.put("cont",cont);
        map.put("page_id",page_id);
        return map;
    }

    /**
     * 激光通讯没用此接口
     */
    @ResponseBody
    @RequestMapping(value="findHttp_Tab_org", method= RequestMethod.GET,produces="application/json;charset=UTF-8")
    public String findHttp(Integer i_id) throws SQLException {
        return this.tab_orgService.list_Http(i_id);
    }

    @Override
    public String getText() {
        return null;
    }
}
